<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="midHostname" value='<%=ServerValue.getMidHostname()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- FLASH -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.flash.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		if ( "" != $("#advId").val() ){
			$(":input[name*='cateLayoutType']").each(function(index){
				if ( this.value == 'FLASH'){
					$("#objId" + (index+1)).flash(
		        { src: "${midHostname}/eventImg/" + $("#cateMainImgFolder" + (index+1)).val() + "/" + $("#advType").val() + "/" + $("#cateMainImgName" + (index+1)).val(),
		          width: 675,
		          height: 310 },
		        { version: 8 }
					);
				}else{
					$("#objId"+(index+1)).html("<img src='${midHostname}/eventImg/" + $("#cateMainImgFolder"+(index+1)).val() + "/" + $("#advType").val() + "/" + $("#cateMainImgName"+(index+1)).val() + "' width='675' height='310'/><br/>");
				}
				$("#objId"+(index+1)).append("<img src='${midHostname}/eventImg/" + $("#cateSubImgFolder"+(index+1)).val() + "/" + $("#advType").val() + "/" + $("#cateSubImgName"+(index+1)).val() + "' width='88' height='73'/><br/>");
			});
		}
		
		//小圖檔案尺寸檢查
		$(":file[name*='cateSubImg']").each(function(index){
			$(this).change(function(){
					var seq = index + 1;
					var cateLayoutTypeId = "cateLayoutType" + seq;
					var cateLayoutType = $("#" + cateLayoutTypeId);
					if ( cateLayoutType.attr("value") != 'FLASH'){
						checkImg(this, 4, 88, 73, $("#imageSubImgCorrect" + seq),"");
					}
				});
		});
		
		//大圖檔案尺寸檢查
		$(":file[name*='cateMainImg']").each(function(index){
			$(this).change(function(){
					var seq = index + 1;
					var cateLayoutTypeId = "cateLayoutType" + seq;
					var cateLayoutType = $("#" + cateLayoutTypeId);
					if ( cateLayoutType.attr("value") != 'FLASH'){
						checkImg(this, 90, 675, 310, $("#imageFileCorrect" + seq),"");
					}
				});
		});
		
		$(":input[name*='cateLayoutType']").change(function(index){
			$("#cateSubImg" + (index+1)).val("");
			$("#cateMainImg" + (index+1)).val("");
			$("#cateSubImgName" + (index+1)).val("");
			$("#cateMainImgName" + (index+1)).val("");
			$("#cateImgFolder" + (index+1)).val("");
		});

		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#mainGoldAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#mainGoldAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#mainGoldAdvForm").submit();
			}
		});
	});
	
	function validate_data(){
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
		}

		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
		}

		for( var i = 1; i <= 4 ; i++ ){
			if ( $("#cateSubImg" + i).val() == "" && $("#cateSubImgName" + i).val() == "" ){
				alert("请输入黄金促销小图" + i);
				$("#cateSubImg" + i).focus();
				return false;
			}
			if ( $("#cateMainImg" + i).val() == "" && $("#cateMainImgName" + i).val() == "" ){
				alert("请输入黄金促销大图" + i);
				$("#cateMainImg" + i).focus();
				return false;
			}
			if ( $("#cateSubImg" + i).val() != "" ){
				if ( $("#cateSubImg" + i).val().toLowerCase().indexOf(".gif") == -1 && $("#cateSubImg" + i).val().toLowerCase().indexOf(".jpg") == -1){
					alert("tab " + i + "小图檔案格式错误,请上传gif/jpg檔");
					return false;
				}
				$("#cateSubImgName"+i).val($("#cateSubImg"+i).val());
			}			
			if ( $("#cateMainImg" + i).val() != "" ){
				if ( $("#cateLayoutType" + i).val() == "FLASH" && $("#cateMainImg" + i).val().toLowerCase().indexOf(".swf") == -1 ){
					alert("tab " + i + "大图檔案格式错误,请上传flash檔");
					return false;
				}
				if ( $("#cateLayoutType" + i).val() == "IMG" && ( $("#cateMainImg" + i).val().toLowerCase().indexOf(".gif") == -1 && $("#cateMainImg" + i).val().toLowerCase().indexOf(".jpg") == -1 )){
					alert("tab " + i + "大图檔案格式错误,请上传gif/jpg檔");
					return false;
				}					
				$("#cateMainImgName"+i).val($("#cateMainImg"+i).val());
			}
			if ( $("#cateImgLink"+i).val() == "" ){
				alert("请输入" + "tab " + i + "图片点击连结" + i);
				$("#cateImgLink"+i).focus();
				return false;
			}
			if ( !isURL($("#cateImgLink" + i).val()) ){
				alert("tab" + i + " 图片点击连结格式有误");
				$("#cateImgLink" + i).focus();
				return false;
			}

			//圖片尺寸檢查
			var seq = i;
			
			//小圖檔案尺寸檢查
			var imageFileInputId = "cateSubImg" + seq;
			var imageFileInput = document.getElementById(imageFileInputId);
			var subImageCorrectHidden = $("#imageSubImgCorrect" + seq);
			
			if ( "" == $("#advId").val() ){
				//新增
				if (imageFileInput.value != '') {
					var subImageErrorMessage = subImageCorrectHidden.val();
					if (subImageErrorMessage != "") {
						alert("tab" + seq + " 黄金促销小图尺寸不正碉：" + subImageErrorMessage);
						return false;
					}
				} else {
					alert("请选择 tab" + seq + " 黄金促销小图");
					return false;
				}
			} else {
				//修改
				if (imageFileInput.value != '') {
					var subImageErrorMessage = subImageCorrectHidden.val();
					if (subImageErrorMessage != "") {
						alert("tab" + seq + " 黄金促销小图尺寸不正碉：" + subImageErrorMessage);
						return false;
					}
				}
			}
			
			//大圖檔案尺寸檢查
			var cateLayoutTypeId = "cateLayoutType" + seq;
			var cateLayoutType = $("#" + cateLayoutTypeId);
			var imageFileInputId = "cateMainImg" + seq;
			var imageFileInput = document.getElementById(imageFileInputId);
			var mainImageCheckResultMessageHolder = $("#imageFileCorrect" + seq);
			var mainImageErrorMessage = mainImageCheckResultMessageHolder.val();
			
			if ( "" == $("#advId").val() ){
				//新增
				if (imageFileInput.value != '') {
					if ( cateLayoutType.attr("value") != 'FLASH'){
						if (mainImageErrorMessage != "") {
							alert("tab" + seq + " 黄金促销大图尺寸不正碉：" + mainImageErrorMessage);
							return false;
						}
					}
				} else {
					alert("请选择 tab" + seq + " 黄金促销大图");
					return false;
				}
			} else {
				//修改
				if ( cateLayoutType.attr("value") != 'FLASH'){
					if (mainImageErrorMessage != "") {
						alert("tab" + seq + " 黄金促销大图尺寸不正碉：" + mainImageErrorMessage);
						return false;
					}
				}
			}

		}
		return true;
	}
</script>
<h1>
	广告管理 - 馆首页广告大看版
	<br/>
	<div class="f-link">
		<a href="${midContextPath}/generate/search.do">回广告查询页</a>
	</div>
</h1>
<s:if test="hasActioneErrors()">
	<p><span class="msg rn"><s:actionerror/></span></p>
</s:if>
<s:if test="hasActionMessages()">
	<span class="msg rn"><s:actionmessage/></span>
</s:if>
<s:form action="mainGold/saveCateMainGoldAdv.do" method="post" name="mainGoldAdvForm" id="mainGoldAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>
					馆首页大看版广告
					<input type="hidden" id="advType" name="advType" value="${advType}"/>
				</td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/></td>
			</tr>
			<tr>
				<th>馆别</th>
				<td>
					<select id="mainCateId" name="mainCateId">
						<c-rt:forEach items="${categoryRoot}" var="category">
							<option value="${category.id}" ${mainCateId eq category.id ? "selected" : ""}>${category.name}</option>
						</c-rt:forEach>
					</select>
					<s:if test="null != fieldErrors['mainCateId']">
					<p><span class="msg rn"><s:fielderror><s:param>mainCateId</s:param></s:fielderror></span></p>
					</s:if>
				</td>
			</tr>			
			<tr>
				<th>起迄时间</th>
				<td>
					<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/> 
					<select id="startTime" name="startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
					</select> ~ 
					<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
					<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
					</select>
					<br/>
					<s:if test="null != fieldErrors['startDate']">
					<p><span class="msg rn"><s:fielderror><s:param>startDate</s:param></s:fielderror></span></p>
					</s:if>					
					<s:if test="null != fieldErrors['endDate']">
					<p><span class="msg rn"><s:fielderror><s:param>endDate</s:param></s:fielderror></span></p>
					</s:if>
				</td>
			</tr>
			<tr>
				<th>tab1图檔设定</th>
				<td>
					<div id="objId1"></div><br/>
					<b>看版内容型态:</b>
					<select name="cateLayoutType1" id="cateLayoutType1">
						<option value="IMG" ${cateLayoutType1 eq 'IMG' ? 'selected' : '' }>图(675X310)</option>
						<option value="FLASH" ${cateLayoutType1 eq 'FLASH' ? 'selected' : '' }>FLASH(675x310)</option>
					</select>
					<s:if test="null != fieldErrors['cateLayoutType1']">
					<p><span class="msg rn"><s:fielderror><s:param>cateLayoutType1</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<b>黄金促销小图:</b>
					<s:file id="cateSubImg1" name="cateSubImg1" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：88 x 73 ,大小：4k以内</span>
					<s:hidden id="imageSubImgCorrect1" ></s:hidden>
					<s:if test="null != fieldErrors['cateSubImg1']">
					<p><span class="msg rn"><s:fielderror><s:param>cateSubImg1</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<b>黄金促销大图/flash:</b><s:file id="cateMainImg1" name="cateMainImg1" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：675 x 310 ,大小：90k以内</span>
					<s:hidden id="imageFileCorrect1" ></s:hidden>
					<s:if test="null != fieldErrors['cateMainImg1']">
					<p><span class="msg rn"><s:fielderror><s:param>cateMainImg1</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<b>图片点击连结:</b><input type="text" name="cateImgLink1" id="cateImgLink1" value="${cateImgLink1}" size="60"/><br/><span class="txt-rd">ex:http://www.yaodian100.com</span>
					<s:if test="null != fieldErrors['cateImgLink1']">
					<p><span class="msg rn"><s:fielderror><s:param>cateImgLink1</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<input type="hidden" id="cateSubImgName1" name="cateSubImgName1" value="${cateSubImgName1}"/>
					<input type="hidden" id="cateMainImgName1" name="cateMainImgName1" value="${cateMainImgName1}"/>
					<input type="hidden" id="cateSubImgFolder1" name="cateSubImgFolder1" value="${cateSubImgFolder1}"/>				
					<input type="hidden" id="cateMainImgFolder1" name="cateMainImgFolder1" value="${cateMainImgFolder1}"/>				
				</td>
			</tr>
			<tr>
				<th>tab2图檔设定</th>
				<td>
					<div id="objId2"></div><br/>
					<b>看版内容型态:</b>
					<select name="cateLayoutType2" id="cateLayoutType2">
						<option value="IMG" ${cateLayoutType2 eq 'IMG' ? 'selected' : '' }>图(675X310)</option>
						<option value="FLASH" ${cateLayoutType2 eq 'FLASH' ? 'selected' : '' }>FLASH(675x310)</option>
					</select>
					<s:if test="null != fieldErrors['cateLayoutType2']">
					<p><span class="msg rn"><s:fielderror><s:param>cateLayoutType2</s:param></s:fielderror></span></p>
					</s:if>						
					<br/>
					<b>黄金促销小图:</b>
					<s:file id="cateSubImg2" name="cateSubImg2" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：88 x 73 ,大小：小于4k</span>
					<s:hidden id="imageSubImgCorrect2" ></s:hidden>
					<s:if test="null != fieldErrors['cateSubImg2']">
					<p><span class="msg rn"><s:fielderror><s:param>cateSubImg2</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>				
					<b>黄金促销大图/flash:</b><s:file id="cateMainImg2" name="cateMainImg2" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：675 x 310 ,大小：90k以内</span>
					<s:hidden id="imageFileCorrect2" ></s:hidden>
					<s:if test="null != fieldErrors['cateMainImg2']">
					<p><span class="msg rn"><s:fielderror><s:param>cateMainImg2</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>
					<b>图片点击连结:</b><input type="text" name="cateImgLink2" id="cateImgLink2" value="${cateImgLink2}" size="60"/><br/><span class="txt-rd">ex:http://www.yaodian100.com</span>
					<s:if test="null != fieldErrors['cateImgLink2']">
					<p><span class="msg rn"><s:fielderror><s:param>cateImgLink2</s:param></s:fielderror></span></p>
					</s:if>	
					<br/>
					<input type="hidden" id="cateSubImgName2" name="cateSubImgName2" value="${cateSubImgName2}"/>
					<input type="hidden" id="cateMainImgName2" name="cateMainImgName2" value="${cateMainImgName2}"/>
					<input type="hidden" id="cateSubImgFolder2" name="cateSubImgFolder2" value="${cateSubImgFolder2}"/>				
					<input type="hidden" id="cateMainImgFolder2" name="cateMainImgFolder2" value="${cateMainImgFolder2}"/>
				</td>
			</tr>
			<tr>
				<th>tab3图檔设定</th>
				<td>
					<div id="objId3"></div><br/>
					<b>看版内容型态:</b>
					<select name="cateLayoutType3" id="cateLayoutType3">
						<option value="IMG" ${cateLayoutType3 eq 'IMG' ? 'selected' : '' }>图(675X310)</option>
						<option value="FLASH" ${cateLayoutType3 eq 'FLASH' ? 'selected' : '' }>FLASH(675x310)</option>
					</select>
					<s:if test="null != fieldErrors['cateLayoutType3']">
					<p><span class="msg rn"><s:fielderror><s:param>cateLayoutType3</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>
					<b>黄金促销小图:</b>
					<s:file id="cateSubImg3" name="cateSubImg3" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：88 x 73 ,大小：4k以内</span>
					<s:hidden id="imageSubImgCorrect3" ></s:hidden>
					<s:if test="null != fieldErrors['cateSubImg3']">
					<p><span class="msg rn"><s:fielderror><s:param>cateSubImg3</s:param></s:fielderror></span></p>
					</s:if>						
					<br/>				
					<b>黄金促销大图/flash:</b><s:file id="cateMainImg3" name="cateMainImg3" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：675 x 310 ,大小：90k以内</span>
					<s:hidden id="imageFileCorrect3" ></s:hidden>
					<s:if test="null != fieldErrors['cateMainImg3']">
					<p><span class="msg rn"><s:fielderror><s:param>cateMainImg3</s:param></s:fielderror></span></p>
					</s:if>						
					<br/>
					<b>图片点击连结:</b><input type="text" name="cateImgLink3" id="cateImgLink3" value="${cateImgLink3}" size="60"/><br/><span class="txt-rd">ex:http://www.yaodian100.com</span>
					<s:if test="null != fieldErrors['cateImgLink3']">
					<p><span class="msg rn"><s:fielderror><s:param>cateImgLink3</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>
					<input type="hidden" id="cateSubImgName3" name="cateSubImgName3" value="${cateSubImgName3}"/>
					<input type="hidden" id="cateMainImgName3" name="cateMainImgName3" value="${cateMainImgName3}"/>
					<input type="hidden" id="cateSubImgFolder3" name="cateSubImgFolder3" value="${cateSubImgFolder3}"/>				
					<input type="hidden" id="cateMainImgFolder3" name="cateMainImgFolder3" value="${cateMainImgFolder3}"/>				
				</td>
			</tr>
			<tr>
				<th>tab4图檔设定</th>
				<td>
					<div id="objId4"></div><br/>
					<b>看版内容型态:</b>
					<select name="cateLayoutType4" id="cateLayoutType4">
						<option value="IMG" ${cateLayoutType4 eq 'IMG' ? 'selected' : '' }>图(675X310)</option>
						<option value="FLASH" ${cateLayoutType4 eq 'FLASH' ? 'selected' : '' }>FLASH(675x310)</option>
					</select>
					<s:if test="null != fieldErrors['cateLayoutType4']">
					<p><span class="msg rn"><s:fielderror><s:param>cateLayoutType4</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>
					<b>黄金促销小图:</b>
					<s:file id="cateSubImg4" name="cateSubImg4" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：88 x 73 ,大小：4k以内</span>
					<s:hidden id="imageSubImgCorrect4" ></s:hidden>
					<s:if test="null != fieldErrors['cateSubImg4']">
					<p><span class="msg rn"><s:fielderror><s:param>cateSubImg4</s:param></s:fielderror></span></p>
					</s:if>					
					<br/>				
					<b>黄金促销大图/flash:</b><s:file id="cateMainImg4" name="cateMainImg4" value="" size="60" ></s:file><br/><span class="txt-rd">建议图片尺寸：675 x 310 ,大小：90k以内</span>
					<s:hidden id="imageFileCorrect4" ></s:hidden>
					<s:if test="null != fieldErrors['cateMainImg4']">
					<p><span class="msg rn"><s:fielderror><s:param>cateMainImg4</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<b>图片点击连结:</b><input type="text" name="cateImgLink4" id="cateImgLink4" value="${cateImgLink4}" size="60"/><br/><span class="txt-rd">ex:http://www.yaodian100.com</span>
					<s:if test="null != fieldErrors['cateImgLink4']">
					<p><span class="msg rn"><s:fielderror><s:param>cateImgLink4</s:param></s:fielderror></span></p>
					</s:if>
					<br/>
					<input type="hidden" id="cateSubImgName4" name="cateSubImgName4" value="${cateSubImgName4}"/>
					<input type="hidden" id="cateMainImgName4" name="cateMainImgName4" value="${cateMainImgName4}"/>		
					<input type="hidden" id="cateSubImgFolder4" name="cateSubImgFolder4" value="${cateSubImgFolder4}"/>				
					<input type="hidden" id="cateMainImgFolder4" name="cateMainImgFolder4" value="${cateMainImgFolder4}"/>		
				</td>
			</tr>
		<c-rt:if test="${not empty advId}">
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${createUser}</p>
					<p>修改：<fmt:formatDate value="${modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${modifyUser}</p>
				</td>
			</tr>
		</c-rt:if>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/search.do">回广告查询页</a>
</div>